/**
 * 
 */
package truerefactor.codesmell;

import java.util.List;

import truerefactor.graph.CodeGraph;
import truerefactor.refactor.Refactoring;
import truerefactor.ui.DisplayInfo;

/**
 * CodeSmell - The Top Level class from which all other code smells
 * implementations derive from.
 * 
 * @author Isaac Griffith
 */
public abstract class CodeSmell implements DisplayInfo {

    /**
     * A short string representation of the code smell's name
     */
    protected String name;
    /**
     * An acronym for the code smell
     */
    protected String shortName;
    /**
     * A short description of the code smell.
     */
    protected String description;

    /**
     * @param graph
     * @return
     */
    public double measure(CodeGraph graph)
    {
        return measure(graph, false, null);
    }

    /*
     * (non-Javadoc)
     * @see truerefactor.refactor.DisplayInfo#getName()
     */
    @Override
    public String getName()
    {
        return name;
    }

    /*
     * (non-Javadoc)
     * @see truerefactor.refactor.DisplayInfo#getDescription()
     */
    @Override
    public String getDescription()
    {
        return description;
    }

    /*
     * (non-Javadoc)
     * @see truerefactor.ui.DisplayInfo#getShortName()
     */
    @Override
    public String getShortName()
    {
        return shortName;
    }

    /**
     * Measures across the specified graph looking for the code smell. This
     * method signifies that the measurements is the initial measurement and
     * that the class should also be deciding, for each found instance of the
     * code smell, how to generate a sequence of refactorings to remove the code
     * smell. This sequence is the added to the provided list of refactoring
     * sequences.
     * 
     * @param graph
     *            CodeGraph to be measured
     * @param sequences
     *            List of sequences of refactorings.
     * @return the number of this code smell found within the provided graph.
     */
    public double initialMeasurement(CodeGraph graph, List<List<Refactoring>> sequences)
    {
        return measure(graph, true, sequences);
    }

    /**
     * Measures across the provided graph looking for the implemented code
     * smell. If found and the provided initial flag is true it then generates a
     * refactoring sequence to remove the code smell and places that sequence in
     * the provided list of refactoring sequences
     * 
     * @param graph
     *            CodeGraph to be measured
     * @param initial
     *            flag specifying whether this is the initial measurement or not
     * @param sequences
     *            List of sequences of refactorings
     * @return the number of this code smell found within the provided graph
     */
    protected abstract double measure(CodeGraph graph, boolean initial, List<List<Refactoring>> sequences);
}
